package ru.tests.betterprogrammer;

/**
 * TODO: add description
 * Date: 12.08.11 22:13
 *
 * @author Alexander Troshanin
 */
public class Task4 {

    public static void main(String[] args) {
        System.out.println(countWaysToJump(1));
        System.out.println(countWaysToJump(2));
        System.out.println(countWaysToJump(3));
        System.out.println(countWaysToJump(4));
        System.out.println(countWaysToJump(5));
        System.out.println(countWaysToJump(6));
        System.out.println(countWaysToJump(7));
        System.out.println(countWaysToJump(8));
        System.out.println(countWaysToJump(9));
        System.out.println(countWaysToJump(10));
    }

    public static int countWaysToJump(int N) {
        /*
          A set of stairs has N steps.
          You can jump either 1 or 2 steps at a time.
          For example, if the stairs is N=4 steps, you can reach the end in 5 possible ways:
          1-1-1-1, or 1-2-1 or 1-1-2 or 2-1-1 or 2-2
          Please implement this method to
          return the count of the different ways to reach the end of the stairs with N steps.
         */

        int possibleCountOfTwo = N / 2;

        int sum = 0;
        for (int cntTwo = 0; cntTwo <= possibleCountOfTwo; cntTwo++) {

            int cntOne = N - cntTwo * 2;

            sum += calculate(cntOne, cntTwo);

        }

        return sum;
    }

    private static int calculate(int cntOne, int cntTwo) {
        if (cntOne == 0 || cntTwo == 0) {
            return 1;
        }

        return (cntOne + 1) + sum(cntOne) * (cntTwo - 1);
    }

    private static int sum(int c) {
        return ((c + 1) * c) / 2;
    }

}
